import request from "./request";
import { useAppStore } from "@/store/app";
import { ElMessage } from "element-plus";

/**
 * get 请求
 * @param {string} api 请求地址
 * @param {obj} params 参数
 * @param {boolean} needLoading 是否需要转TM的圈圈
 * @returns 返回请求结果
 */
export const getQuery = async (
  api: string,
  params = {},
  needLoading = false
) => {
  const res = await request.get(api, {
    params,
  });

  if (res.success !== true) {
    ElMessage.error(res.msg || "网络请求错误");
    return false;
  } else {
    return res;
  }
};

/**
 * post 请求
 * @param {string} api 请求地址
 * @param {obj} params 参数
 * @param {boolean} needLoading 是否需要转TM的圈圈
 * @returns 返回请求结果
 */
export const postSomeThing = async (api: string, params = {}) => {
  const res = await request.post(api, params);
  if (res.success !== true) {
    ElMessage.error(res.msg || "网络请求错误");
    return false;
  } else {
    return res;
  }
};
